package test.wechat.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lodsve.wechat.beans.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import test.wechat.service.WeixinService;

import java.util.List;

/**
 * .
 *
 * @author sunhao(sunhao.java@gmail.com)
 * @version V1.0, 16/3/4 下午1:22
 */
@Api(value = "微信菜单API测试", description = "微信菜单API测试")
@RestController
@RequestMapping("/weixin/menu")
public class MenuController {
    @Autowired
    private WeixinService weixinService;

    @ApiOperation(value = "获取微信菜单列表", notes = "获取微信菜单列表")
    @ApiResponses({@ApiResponse(code = 200, message = "获取微信菜单列表成功")})
    @RequestMapping(value = "/list", method = RequestMethod.GET, produces = "application/json")
    public List<Menu> getMenus() {
        return weixinService.getMenus();
    }

    @ApiOperation(value = "新增微信菜单列表", notes = "新增微信菜单列表")
    @ApiResponses({@ApiResponse(code = 200, message = "新增微信菜单列表成功")})
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json")
    public void saveMenu(@ApiParam(name = "menu", value = "需要保存的微信菜单") @RequestBody List<Menu> menus) {
        weixinService.saveMenus(menus);
    }

    @ApiOperation(value = "删除微信菜单列表", notes = "删除微信菜单列表")
    @ApiResponses({@ApiResponse(code = 200, message = "删除微信菜单列表成功")})
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE, produces = "application/json")
    public void delete() {
        weixinService.deleteMenus();
    }
}
